package com.example.fp.zlz.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.fp.cgc.entity.PageCondition;
import com.example.fp.zlz.entity.PageConditionGame;
import com.example.fp.zlz.entity.Author;
import com.example.fp.zlz.entity.Game;
import com.example.fp.zlz.entity.Gametype;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 说明: game表操作接口
 * 编写人: 张连壮
 * 编写时间: 2019-12-31
 * 修改时间:
 * 接口
 */
@Mapper
public interface GameMapper extends BaseMapper<Game> {
	@Select("select * from game")
	List<Game> selectallgame();

	@Select("select author as name,count(*) as value from game group by author order by value desc limit 10")
	List<Author> selectgameauthor();

	//	@Select("select category as cname,count(*) as value from game group by category")
//	List<Gametype> selectgamecategory();
	@Select("(select gname,score,category,grank from game where category ='休闲'order by grank asc limit 10)\n" +
			"union\n" +
			"(select gname,score,category,grank from game where category='动作'order by grank asc limit 10)\n" +
			"union\n" +
			"(select gname,score,category,grank from game where category='冒险' order by grank asc limit 10)")
	List<Gametype> selectbytype();

	@Select("<script>" +
			"select * from game" +
			"            <if test=\"start!=null and size!=null\">\n" +
			"                limit #{start},#{size}\n" +
			"            </if>\n" +
			"</script>")
	List<Game> selectGameListPage(PageConditionGame pageConditionGame);

	@Select("select count(*) from game")
	int selectgamesum();

	@Select("select t.rn from (\n" +
			"    select *,row_number()\n" +
			"        over (order by id) rn from game) t\n" +
			" where t.id = #{id}")
	int getGameIndex(int id);

	@Select("<script>" +
			"select count(*) from game" +
			"         <where>" +
			"            <if test=\"gname != null and gname != ''\">" +
			"gname LIKE CONCAT('%',#{gname},'%')" +
			"            </if>" +
			"         </where>" +
			"</script>")
	int getGameByName(String gname);
	@Select("<script>" +
			"select " +
			"id," +
			"gname," +
			"author," +
			"score," +
			"description," +
			"category," +
			"grank" +
			" from game" +
			"<where>" +
			"<if test=\"gname != null and gname != ''\">" +
			"gname LIKE CONCAT('%',#{gname},'%')" +
			"</if>" +
			"</where>" +
			"<if test=\"start!=null and size!=null\">" +
			"limit #{start},#{size}" +
			"</if>" +
			"</script>")
	List<Game>selectSearchGamePage(PageConditionGame pageConditionGame);
}